var _iframeWin;

//工具方法
Date.prototype.format = function (format) {
    var o = {
        "M+" : this.getMonth()+1, //月份
        "d+" : this.getDate(), //日
        "h+" : this.getHours()%12 == 0 ? 12 : this.getHours()%12, //小时
        "H+" : this.getHours(), //小时
        "m+" : this.getMinutes(), //分
        "s+" : this.getSeconds(), //秒
        "q+" : Math.floor((this.getMonth()+3)/3), //季度
        "S" : this.getMilliseconds() //毫秒
    };
    if (/(y+)/.test(format)) format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(format)) format = format.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return format;
}

function stringToDate(str){
    str = str.replace(/-/g,'/'); 
    return new Date(str);
}



Array.prototype.deleteValue=function(val){
    var arr=this;
    for(var i=0;i<arr.length;i++){
        if(val==arr[i]){
            arr.splice(i,1);
            break;
        }
    }
}

stringIsEmpty=function (str) {
    return str==undefined || str.length==0;
}

function ajaxData(method,url,formData,succFunc,ajaxConfig,errorFunc) {
    $.ajax({
        url:url,
        type:method,
        contentType: "application/json; charset=utf-8",
        data:formData,
        success:function (data) {
            var resultCodeName='resultCode',messageName='message';
            if(ajaxConfig!=undefined){
                resultCodeName=ajaxConfig.resultCodeName;
                messageName=ajaxConfig.messageName;
            }
            if(data[resultCodeName]==0){
                succFunc(data)
            }else{
                if(errorFunc!=undefined){
                    errorFunc(data)
                }else{
                    var msg=data[messageName];
                    if(msg==undefined)msg='数据请求出错';
                    layui.layer.msg(msg);
                }

            }
        },error:function (data) {
            if(errorFunc!=undefined){
                errorFunc(data);
            }else{
                layui.layer.msg('load data error:'+JSON.stringify(data));
            }

        }
    });
}

function stringToArray(str){
    if(stringIsEmpty(str))return [];
    return str.split(',');
}

function arrayToString(arr){
    if(arr==undefined || arr.length==0)return '';
    var str='';
    for(var i=0;i<arr.length;i++){
        str+=arr[i];
        if(i<arr.length-1)str+=',';
    }
    return str;
}

function openWin(url) {
    //添加数据
    var layer=layui.layer;
    layer.open({
        type: 2,
        title: ' ',
        shadeClose: false,
        shade: 0.8,
        area: ['800px', '86%'],
        content: url //iframe的url
        ,zIndex: layer.zIndex //重点1
        ,success: function(layero){
            layer.setTop(layero); //重点2
        },btnAlign:'c'
        ,btn:['确定','重置']
        ,yes: function(index, layero){
            //var body = layer.getChildFrame('body', index);
            //body.contents().find("#url").val(111);
            _iframeWin.postData();
            //layer.close(index);
        },btn2: function(index, layero){
            _iframeWin.resetData();
            return false;
        },success:function(layero, index){
            var iframeWin = window[layero.find('iframe')[0]['name']];
            _iframeWin=iframeWin;
            //iframeWin.childSelectIcon('123456');
        }
    });
}


function openBrowseWin(url) {
    //添加数据
    var layer=layui.layer;
    layer.open({
        type: 2,
        title: ' ',
        shadeClose: false,
        shade: 0.8,
        area: ['800px', '86%'],
        content: url //iframe的url
        ,zIndex: layer.zIndex //重点1
        ,success: function(layero){
            layer.setTop(layero); //重点2
        }
    });
}